// router.js
import {RouterMount,createRouter} from 'uni-simple-router';
import store from '@/store'

const router = createRouter({
    platform: process.env.VUE_APP_PLATFORM,
    routes: [
        ...ROUTES,
        {
            path: '*',
            redirect:(to)=>{
                return {name:'404'}
            }
        },
    ]
});
//全局路由前置守卫
router.beforeEach((to, from, next) => {
    if(!to.meta.login){
        next();
    }else {
        /*next();*/
        //console.log(store.state.userinfo);
        if(store.state.userinfo && store.state.userinfo.userId){
            next();
        }else {
            //next({path:"/pages/login/login?code=2&backUrl="+to.path,query:{code:2,backUrl:to.path}});
            //next({name:"login",params:{code:2,backUrl:to.path}});
            next({path:"/pages/login/login",query:{code:2,backUrl:to.path}});
        }
    }

});
// 全局路由后置守卫
router.afterEach((to, from) => {
    console.log('跳转结束')
})

export {
    router,
    RouterMount
}
